﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtOfTest.WebAii.Controls.HtmlControls;

namespace SM2SetupSearch
{
    public class BulkEditActions
    {
        public static void ChangeTo(string strItem)
        {            
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv cphPageContent_pnlMassEdit = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("cphPageContent_pnlMassEdit");
            HtmlDiv Div1 = cphPageContent_pnlMassEdit.Find.ById<HtmlDiv>("Div1");
            IList<HtmlAnchor> iListAnchor = Div1.Find.AllByAttributes<HtmlAnchor>();
            switch (strItem)
            {
                case SetupSearch.DATES:
                    for (int i = 0; i < iListAnchor.Count; i++)
                    {
                        HtmlAnchor btn = iListAnchor[i];
                        string strLabelButton = btn.GetValue("href", "blank");
                        if (strLabelButton != null && strLabelButton.Contains(SetupSearch.DATES))
                        {
                            SM2Input.Tradition.ClickAnchor(btn);
                            break;
                        }
                    }
                    break;

                case SetupSearch.LANGUAGES:
                    for (int i = 0; i < iListAnchor.Count; i++)
                    {
                        HtmlAnchor btn = iListAnchor[i];
                        string strLabelButton = btn.GetValue("href", "blank");
                        if (strLabelButton != null && strLabelButton.Contains(SetupSearch.LANGUAGES))
                        {
                            SM2Input.Tradition.ClickAnchor(btn);
                            break;
                        }
                    }
                    break;

                case SetupSearch.COUNTRIES:
                    for (int i = 0; i < iListAnchor.Count; i++)
                    {
                        HtmlAnchor btn = iListAnchor[i];
                        string strLabelButton = btn.GetValue("href", "blank");
                        if (strLabelButton != null && strLabelButton.Contains(SetupSearch.COUNTRIES))
                        {
                            SM2Input.Tradition.ClickAnchor(btn);
                            break;
                        }
                    }
                    break;

                default:
                    break;
            }
        }

        public static void SetDateFrom(string strDate)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv cphPageContent_pnlMassEdit = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("cphPageContent_pnlMassEdit");
            HtmlDiv cphPageContent_pnlScroll = cphPageContent_pnlMassEdit.Find.ById<HtmlDiv>("cphPageContent_pnlScroll");
            
            switch (strDate)
            {
                case "LeaseAsIs":
                    HtmlInputRadioButton cphPageContent_rbFromAsIs = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbFromAsIs");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbFromAsIs);
                    break;

                case "Clear":
                    HtmlInputRadioButton cphPageContent_rbFromClear = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbFromClear");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbFromClear);
                    break;

                default:
                    HtmlInputRadioButton cphPageContent_rbFromOverwrite = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbFromOverwrite");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbFromOverwrite);
                    HtmlInputText cphPageContent_tbDateFromME = cphPageContent_pnlScroll.Find.ById<HtmlInputText>("cphPageContent_tbDateFromME");
                    SM2Input.Tradition.TypeTextIntoTextFieldWithHint(cphPageContent_tbDateFromME, strDate);
                    break;
            }
        }

        public static void SetDateTo(string strDate)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv cphPageContent_pnlMassEdit = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("cphPageContent_pnlMassEdit");
            HtmlDiv cphPageContent_pnlScroll = cphPageContent_pnlMassEdit.Find.ById<HtmlDiv>("cphPageContent_pnlScroll");

            switch (strDate)
            {
                case "LeaseAsIs":
                    HtmlInputRadioButton cphPageContent_rbToAsIs = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbToAsIs");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbToAsIs);
                    break;

                case "Clear":
                    HtmlInputRadioButton cphPageContent_rbToClear = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbToClear");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbToClear);
                    break;

                default:
                    HtmlInputRadioButton cphPageContent_rbToOverwrite = cphPageContent_pnlScroll.Find.ById<HtmlInputRadioButton>("cphPageContent_rbToOverwrite");
                    SM2Input.Tradition.SelectRadio(cphPageContent_rbToOverwrite);
                    HtmlInputText cphPageContent_tbDateToME = cphPageContent_pnlScroll.Find.ById<HtmlInputText>("cphPageContent_tbDateToME");
                    SM2Input.Tradition.TypeTextIntoTextFieldWithHint(cphPageContent_tbDateToME, strDate);
                    break;
            }
        }
    }
}
